package com.example.zhunongzonghe.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//    @Autowired
//    private JwtTokenInterceptor jwtTokenInterceptor;
//
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        // 注册拦截规则
//        InterceptorRegistration ir = registry.addInterceptor(jwtTokenInterceptor);
//        // 拦截路径，开放api请求的路径都拦截
//        ir.addPathPatterns("/**");
//        // 不拦截路径，如：注册、登录、忘记密码等
//        ir.excludePathPatterns("/Login/**","/file/**","/token/**","/register/**","/Alipay/**");
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry
                .addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET","POST","DELETE","PUT")
                .allowedHeaders("*")
                .maxAge(3600);
    }
}
